var express = require('express');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var Index = require('./routes/index.js');
var Consts = require("./config/consts.json");

var App = express();

App.use(logger('dev'));
App.use(bodyParser.json());
App.use(bodyParser.urlencoded({extended: false}));
App.use(cookieParser());
App.use(express.static(path.join(__dirname, 'html5')));

App.use(Consts.app_uri, Index);

// catch 404 and forward to error handler
App.use(function (req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

App.use(function (err, req, res, next) {
    res.status(err.status || 500);
    res.end(err.message);
});


module.exports = App;
